// pages/myself/shop/shopDetails.js
var utils = require('../../../utils/utils.js');
var Zan = require('../../../dist/index');

Page(Object.assign({}, Zan.TopTips, {

  /**
   * 页面的初始数据
   */
  data: {
    details: null,
    openTime: "",
    closeTime: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var res = wx.getStorageSync('shop_details')
    this.setData({
      details: res,
      openTime: utils.formatDate03(new Date(res.openTime)),
      closeTime: utils.formatDate03(new Date(res.closeTime))
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 预览图片点击事件
  imgTapPreview: function (e) {
    var urls = [];
    var current = e.target.dataset.url;
    var tagFrom = e.target.dataset.urls;
    for (var i = 0; i < tagFrom.length; i++) {
      urls.push(tagFrom[i].smallImgUrl);
    }
    if (typeof (urls) != 'undefined' && urls.length > 0) {
      wx.previewImage({
        current: current,
        urls: urls // 需要预览的图片http链接列表
      })
    }
  },

  goMap: function (e) {
    //114.30125,30.525687
    //<input type="text" id= "add-text1" value= "114.300917,30.529462" class="form-control input-large" name= "addressGeo" >
    var site = e.currentTarget.dataset.site;
    var name = e.currentTarget.dataset.name;
    var address = this.data.details.province + this.data.details.city + this.data.details.district + this.data.details.address;
    var addressGeo = site.split(",");
    wx.openLocation({
      type: 'wgs84 ',
      latitude: parseFloat(addressGeo[1]),
      longitude: parseFloat(addressGeo[0]),
      // latitude: 30.525687,
      // longitude: 114.30125,
      name: name,
      address: address,
      scale: 18
    });
  }
}))